home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-10-25 | 61.0 KB | 2,351 lines | [TEXT/MPS ] |
- {$P}
- {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]}
- { UPrinting.inc1.p }
- { Copyright © 1986-1990 by Apple Computer, Inc. All rights reserved. }
-
- {
- Segmentation strategy:
-
- PrintRes Resident
- PrintMain Resident and used at initialization
- PrintActual Used only during Actual Printing (imaging/spooling)
- PrintImage Used during imaging only
- PrintSpool Used only during printing of a Spool File
- PrintDebug Debugging code
- PrintFinder Code only ever accessed from Finder Printing
- PrintInit One-time Initialization Code
- PrintOpen Code accessed when opening new document
- PrintNonRes General non-resident code
- PrintDoCommand Code for Page Setup command
- PrintTerminate One-time-only code, called only at Termination time
-
- }
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintRes}
-
- PROCEDURE TPrintCommand.DoIt;
-
- VAR
- proceed: BOOLEAN;
-
- BEGIN
- IF fStdPrintHandler.Print(fCmdNumber, proceed) <> NIL THEN; { discard result }
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintSelCommand}
-
- PROCEDURE TPrintCommand.IPrintCommand(itsCmdNumber: CmdNumber;
- itsStdPrintHandler: TStdPrintHandler);
-
- BEGIN
- INoChangesCommand(itsCmdNumber, itsStdPrintHandler.fDocument, itsStdPrintHandler.fView, NIL);
- fStdPrintHandler := itsStdPrintHandler;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAFields}
-
- PROCEDURE TPrintCommand.Fields(PROCEDURE DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
-
- BEGIN
- DoToField('TPrintCommand', NIL, bClass);
- DoToField('fStdPrintHandler', @fStdPrintHandler, bObject);
- INHERITED Fields(DoToField);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintActual}
- {$Push}
- {$IFC qTrace}{$D+}{$ENDC} { No tracing till we get the port straightened out since the current
- port could already be disposed (Thank you Direct connect ImageWriter!) }
-
- PROCEDURE IdleProcForTStdPrintHandler;
- VAR
- savedPort: GrafPtr;
-
- BEGIN
- IF gJobPrintHandler <> NIL THEN
- BEGIN
- GetPort(savedPort);
- SetPort(gWorkPort); { Nice safe port in a storm }
- gJobPrintHandler.DoPrintIdling; { Forward to the current print job handler }
- SetPort(savedPort);
- END;
- END;
- {$Pop}
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintActual}
-
- PROCEDURE TStdPrintHandler.DoPrintIdling;
-
- CONST
- myDlgMask = mDownMask + mUpMask + keyDownMask + keyUpMask + autoKeyMask;
-
- VAR
- ch: CHAR;
- keycode: INTEGER;
- aDialog: DialogPtr;
- anEvent: EventRecord;
- item: INTEGER;
- theItem: Handle;
- itemType: INTEGER;
- box: Rect;
- dontCare: LONGINT;
-
- BEGIN
- IF gApplication.GetEvent(myDlgMask, 0, NIL, anEvent) THEN
- BEGIN
- { Workaround for LaserWriter driver bug: it tries to set GhostWindow
- so that its status window is invisible. Unfortunately, it doesn't
- always set it, so IsDialogEvent returns FALSE (the status window
- is frontmost). If ours isn't already in front, force it there. }
- IF fPrintDialog <> FrontWindow THEN
- gApplication.SelectWMgrWindow(fPrintDialog);
-
- CASE anEvent.what OF
- keyDown:
- WITH anEvent DO
- BEGIN
- ch := CHR(BAND(message, charCodeMask));
- keycode := BSR(BAND(message, keyCodeMask), 8);
- IF ((ch = '.') & (BAND(modifiers, cmdKey) <> 0)) | ((ch = chEscape) & (keycode =
- kEscapeVirtualCode)) THEN
- BEGIN
- IF gFinderPrinting THEN
- item := cancel { Want the 'Cancel All' button }
- ELSE
- item := 1; { Want the 'Cancel' button }
-
- { Flash the appropriate button }
- GetDItem(fPrintDialog, item, itemType, theItem, box);
- HiliteControl(ControlHandle(theItem), 10);
- Delay(8, dontCare);
- HiliteControl(ControlHandle(theItem), 0);
-
- PrSetError(iPrAbort);
- gCancelAllPrinting := TRUE;
- END;
- END;
- OTHERWISE
- IF IsDialogEvent(anEvent) & DialogSelect(anEvent, aDialog, item) & (aDialog =
- fPrintDialog) THEN
- CASE item OF
- 1:
- PrSetError(iPrAbort); { Cancel }
-
- cancel:
- BEGIN { Cancel All Printing }
- PrSetError(iPrAbort);
- gCancelAllPrinting := TRUE;
- END;
-
- END;
- END;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintActual}
-
- PROCEDURE TStdPrintHandler.ChkPrintErr(VAR err: OSErr;
- VAR proceed: BOOLEAN;
- VAR ranOutOfSpace: BOOLEAN);
-
- BEGIN
- IF proceed THEN
- BEGIN
- err := PrError;
- IF err <> noErr THEN
- BEGIN
- {$IFC qDebug}
- IF gDebugPrinting THEN
- WriteLn('Error from PrError is ', err: 1);
- {$ENDC}
- proceed := FALSE;
- IF err = - 1 { iPrSavPFil } THEN
- ranOutOfSpace := TRUE;
- END;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintRes}
-
- PROCEDURE TStdPrintHandler.GetDriverName(VAR driverName: Str255);
-
- VAR
- driverHandle: StringHandle;
-
- BEGIN
- driverHandle := GetString(kPrintDriverName); { Get current driver }
-
- { Be a little cautious, in case we accidentally pick up something
- which is not what we expect, or we can't find it. }
- IF (driverHandle <> NIL) & (LENGTH(driverHandle^^) < 64) THEN
- {$Push} {$H-}
- CopyStr255(driverHandle^^, @driverName)
- {$Pop}
- ELSE
- driverName := '';
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintInit}
- { Initialize the printing unit. Call exactly once }
-
- PROCEDURE InitUPrinting;
-
- VAR
- err: OSErr;
- aStdPrintHandler: TStdPrintHandler;
-
- BEGIN
- gCancelAllPrinting := FALSE;
- gFinderHPrint := NIL;
- gJobPrintHandler := NIL;
-
- SetRect(gStdPageMargins, 72, 72, - 72, - 72); { 1" margins std default }
-
- WITH gBreaksPenState DO
- BEGIN
- pnLoc := gZeroPt;
- pnSize := Point($00020002);
- pnMode := patCopy;
- StuffHex(@pnPat, 'CC663399CC663399');
- END;
-
- gCouldPrint := TRUE;
-
- gUPrintingInitialized := TRUE;
-
- IF gPrintHandler = gNullPrintHandler THEN
- BEGIN { Install a StdPrintHandler in UMacApp
- global variable gPrintHandler }
- New(aStdPrintHandler);
- FailNIL(aStdPrintHandler);
- aStdPrintHandler.IStdPrintHandler(NIL, NIL, kSquareDots, kFixedSize, kFixedSize);
- aStdPrintHandler.fFinderJobDialog := TRUE;
- gPrintHandler := aStdPrintHandler;
- END;
-
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAPrintingRes}
- { Synonym For InitUPrinting }
-
- PROCEDURE InitPrinting;
-
- BEGIN
- InitUPrinting;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintSpool}
-
- PROCEDURE TStdPrintHandler.PrintSpoolFile(anHPrint: Handle;
- VAR err: OSErr;
- VAR proceed: BOOLEAN);
-
- VAR
- prStatus: TPrStatus;
- b: BOOLEAN;
-
- BEGIN
- proceed := TRUE;
- PRPicFile(THPrint(anHPrint), NIL, NIL, NIL, prStatus);
- ChkPrintErr(err, proceed, b);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintOpen}
-
- PROCEDURE TStdPrintHandler.IStdPrintHandler(itsDocument: TDocument;
- itsView: TView;
- itsSquareDots, itsHFixedSize, itsVFixedSize: BOOLEAN);
-
- VAR
- fi: FailInfo;
-
- PROCEDURE HdlInitFailed(error: OSErr;
- message: LONGINT);
-
- BEGIN
- Free;
- END;
-
- BEGIN
- {$IFC qDebug}
- IF NOT gUPrintingInitialized THEN
- BEGIN
- ProgramBreak('InitUPrinting must be called before creating a print handler.');
- Failure(noErr, 0);
- END;
- {$ENDC}
-
- fPrintDialog := NIL;
- fPPrPort := NIL;
- fHPrint := NIL;
- IPrintHandler(itsView);
- fDocument := itsDocument;
-
- CatchFailures(fi, HdlInitFailed);
-
- fStartPage := 1;
- fPageDirection := v; { Page 2 is below page 1, etc. }
- fShowBreaks := FALSE;
- fFixedSizePages[h] := itsHFixedSize;
- fFixedSizePages[v] := itsVFixedSize;
-
- fPrinterDev := kNeverInitialized;
-
- fLastPrinterName := NIL;
- fFinderSetup := FALSE;
- fFinderJobDialog := FALSE;
- {$Push} {$H-}
- fSquareDots := itsSquareDots;
- SetPt(fLastStrip, MAXINT, MAXINT);
- fLastBreak := gZeroVPt;
- {$Pop}
-
- fPageAreas.theMargins := gStdPageMargins;
- fMarginRes.h := 72;
- fMarginRes.v := 72;
- fMinimalMargins := FALSE;
-
- fLastCheckedPrinter := 0;
- IF itsView <> NIL THEN
- BEGIN
- { allocates a handle for the print-info, and sets my field fHPrint accordingly }
- SetDefaultPrintInfo;
-
- IF itsDocument <> NIL THEN
- BEGIN
- IF itsDocument.fDocPrintHandler = NIL THEN
- itsDocument.fDocPrintHandler := SELF;
- IF itsDocument.fPrintInfo = NIL THEN
- IF itsDocument.fSharePrintInfo THEN
- itsDocument.fPrintInfo := fHPrint;
- END;
-
- fView.AttachPrintHandler(SELF);
- END;
-
- Success(fi);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintClose}
-
- PROCEDURE TStdPrintHandler.Free; OVERRIDE;
-
- VAR
- dontDispose: BOOLEAN;
- itsDocument: TDocument;
-
- BEGIN
- dontDispose := fView <> NIL;
- IF dontDispose THEN
- BEGIN
- IF fView.fPrintHandler = SELF THEN
- fView.AttachPrintHandler(gNullPrintHandler);
- fView := NIL;
-
- itsDocument := fDocument;
- dontDispose := itsDocument <> NIL;
- IF dontDispose THEN
- BEGIN
- IF itsDocument.fDocPrintHandler = SELF THEN
- itsDocument.fDocPrintHandler := NIL;
- dontDispose := itsDocument.fSharePrintInfo;
- END;
- IF dontDispose THEN
- dontDispose := itsDocument.fPrintInfo = fHPrint;
- fDocument := NIL;
-
- END;
- IF NOT dontDispose THEN
- fHPrint := DisposeIfHandle(fHPrint);
- fHPrint := NIL; { Always drop my reference }
-
- Handle(fLastPrinterName) := DisposeIfHandle(fLastPrinterName);
-
- BanishPrintDialog;
-
- IF gJobPrintHandler = SELF THEN { let's be safe }
- gJobPrintHandler := NIL;
-
- INHERITED Free;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintImage}
-
- PROCEDURE TStdPrintHandler.AdornPage;
- {$IFC qDebug}
-
- CONST
- botSlop = 8; { ??? Arbitrary choice }
-
- VAR
- heading: Str255;
- pgStr: Str255;
- handyRect: Rect;
- xLoc: INTEGER;
- itsWidth: INTEGER;
- rPlusL: INTEGER;
- itsBottom: INTEGER;
- theFontInfo: FontInfo;
- theTextRect: Rect;
- {$ENDC}
-
- BEGIN
- {$IFC qDebug}
- IF gDebugPrinting THEN { Print extra stuff if debugging }
- BEGIN
- NumToString(fFocusedPage, pgStr);
- TextFont(applFont);
- TextFace([]);
- TextSize(12);
- heading := CONCAT('-', pgStr, '-'); { ??? Make easier for client to change this
- }
-
- { • draw the heading }
- itsWidth := StringWidth(heading);
- WITH fPageAreas.thePaper DO
- rPlusL := right + left;
- itsBottom := fPageAreas.theInk.bottom - botSlop;
- GetFontInfo(theFontInfo);
- {$Push} {$H-}
- WITH theTextRect, theFontInfo DO
- BEGIN
- left := (rPlusL - itsWidth) DIV 2;
- top := itsBottom - ascent;
- right := left + itsWidth;
- bottom := itsBottom + descent;
- END;
- {$Pop}
- MADrawString(@heading, theTextRect, teJustSystem);
-
- { Additionally frame the printable area of the page if gDebugPrinting }
- handyRect := fPageAreas.theInk;
- PenSize(1, 1);
- FrameRect(handyRect);
-
- { Frame the 'interior' of the page }
- PenSize(2, 2);
- handyRect := fPageAreas.theInterior;
- FrameRect(handyRect);
- END;
- {$ENDC}
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintActual}
-
- PROCEDURE TStdPrintHandler.BanishPrintDialog;
-
- BEGIN
- IF fPrintDialog <> NIL THEN
- BEGIN
- IF fPrintDialog = thePort THEN { Only need to invalidate focus if freed
- dialog is the current port }
- BEGIN
- gApplication.InvalidateFocus;
- SetPort(gWorkPort);
- END;
- DisposDialog(fPrintDialog);
- fPrintDialog := NIL;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintRes}
-
- FUNCTION TStdPrintHandler.BreakFollowing(vhs: VHSelect;
- prevBreak: VCoordinate;
- VAR automatic: BOOLEAN): VCoordinate; OVERRIDE;
- { Called from fView.DoBreakFollowing, }
-
- VAR
- orthoVHS: VHSelect;
- newLoc: VCoordinate;
-
- BEGIN
- orthoVHS := gOrthogonal[vhs];
- automatic := TRUE;
- newLoc := Min(prevBreak + fViewPerPage.vh[orthoVHS], fPrintExtent.botRight.vh[orthoVHS]);
-
- {$IFC qDebug}
- IF newLoc <= prevBreak THEN
- BEGIN
- WriteLn('No advance in BreakFollowing; vhs = ', ORD(vhs): 1, ' prevBreak = ', prevBreak: 1,
- ' newLoc = ', newLoc: 1, ' view size: ', fPrintExtent.botRight.vh[orthoVHS]: 1);
- ProgramBreak('No advance in BreakFollowing');
- END;
- {$ENDC}
-
- BreakFollowing := newLoc;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintNonRes}
-
- PROCEDURE TStdPrintHandler.CalcPageStrips(VAR pageStrips: Point); OVERRIDE;
-
- VAR
- vhs, ortho: VHSelect;
- nStrips: INTEGER;
-
- FUNCTION FindLimit(loc: VCoordinate;
- automatic: BOOLEAN): BOOLEAN;
-
- BEGIN
- nStrips := nStrips + 1;
- FindLimit := FALSE;
- END;
-
- BEGIN
-
- { If pages are of fixed size, then simple divide the total size by the
- page size. Otherwise, count up the page breaks one by one. }
-
- FOR vhs := v TO h DO
- BEGIN
- ortho := gOrthogonal[vhs];
- IF fFixedSizePages[ortho] THEN
- {$Push} {$H-}
- WITH fPrintExtent, fViewPerPage DO
- pageStrips.vh[vhs] := (botRight.vh[ortho] - topLeft.vh[ortho] + vh[ortho] - 1) DIV
- vh[ortho]
- {$Pop}
- ELSE
- BEGIN
- nStrips := 0;
- EachBreak(vhs, TRUE, FindLimit);
- pageStrips.vh[vhs] := nStrips;
- END;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintNonRes}
-
- PROCEDURE TStdPrintHandler.CalcViewPerPage(VAR amtPerPage: VPoint); OVERRIDE;
-
- VAR
- vhs: VHSelect;
-
- BEGIN
- WITH fPageAreas DO
- {$Push} {$H-}
- FOR vhs := v TO h DO
- amtPerPage.vh[vhs] := MAX(1, ((ORD4(thePaper.botRight.vh[vhs] - thePaper.topLeft.vh[vhs]
- - ABS(theMargins.topLeft.vh[vhs]) -
- ABS(theMargins.botRight.vh[vhs])))));
- {$Pop}
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintRes}
-
- PROCEDURE TStdPrintHandler.CheckPrinter; OVERRIDE;
-
- VAR
- oldPageAreas: PageAreas;
- oldPrinterDev: INTEGER;
- oldDevRes: Point;
- oldMarginRes: Point;
- didChange: BOOLEAN;
- msgSent: BOOLEAN;
- driverName: Str255;
- aRect, bRect: Rect;
-
- PROCEDURE ItChanged(aView: TView); { this msg is sent to all views if my
- associated document is the kind where one
- copy of the PrintInfo is shared among all
- views }
-
- BEGIN
- aView.DoPrinterChanged;
- END;
-
- BEGIN
- oldPageAreas := fPageAreas;
- oldPrinterDev := fPrinterDev;
- oldDevRes := fDeviceRes;
- oldMarginRes := fMarginRes;
-
- { It costs an open and several LoadResources to call PrValidate. Before
- doing so, check to see if the printer has actually changed. }
- IF fLastCheckedPrinter < gLastDeskAcc THEN { If we haven't checked printer since the }
- BEGIN { last time the Chooser might have run… }
- GetDriverName(driverName);
- {$Push} {$H-} { EqualString does NOT move memory }
- IF (fLastPrinterName = NIL) | (NOT EqualString(fLastPrinterName^^, driverName, FALSE,
- TRUE)) THEN
- {$Pop}
- BEGIN { Printer name has changed… }
- Handle(fLastPrinterName) := DisposeIfHandle(fLastPrinterName); { out with the old }
- fLastPrinterName := NewString(driverName); { in with the new }
- FailNIL(fLastPrinterName);
- ValidatePrintRecord(didChange); { …and validate the print record. }
- END;
- fLastCheckedPrinter := TickCount;
- END;
-
- WITH THPrint(fHPrint)^^ DO
- {$Push} {$H-}
- BEGIN
- fPageAreas.thePaper := rPaper;
-
- {$IFC FALSE}
- { This *old* computation for fMarginRes doesn't work with the current printer drivers,
- so use prInfo's iHRes & iVRes. It's conceivable that this computation was correct
- for some *older* versions of the printer drivers. But what versions???
- NOTE: the Print Shop recommends always using the latest version of the print drivers,
- even with older systems. }
- WITH fPageAreas.thePaper, fMarginRes DO { Recompute effective device resolution }
- BEGIN
- h := (IntMultiply(iPrPgFract, right - left)) DIV prStl.iPageH;
- v := (IntMultiply(iPrPgFract, bottom - top)) DIV prStl.iPageV;
- END;
- {$ENDC}
-
- WITH prInfo, fMarginRes DO { Store latest data from MacPrint prInfo
- record into my own instance variables }
- BEGIN
- h := iHRes; { read the new device resolution values }
- v := iVRes;
-
- fPrinterDev := iDev;
- SetPt(fDeviceRes, iHRes, iVRes);
- WITH fPageAreas DO
- BEGIN
- theInk := rPage;
- IF NOT fMinimalMargins THEN
- SetRect(theMargins, IntMultiply(theMargins.left, h) DIV oldMarginRes.h,
- IntMultiply(theMargins.top, v) DIV oldMarginRes.v,
- IntMultiply(theMargins.right, h) DIV oldMarginRes.h,
- IntMultiply(theMargins.bottom, v) DIV oldMarginRes.v);
- END;
- END;
- {$Pop}
- END;
-
- aRect := fPageAreas.thePaper;
- bRect := fPageAreas.theInk;
- IF (NOT EqualRect(aRect, oldPageAreas.thePaper)) | (NOT EqualRect(bRect, oldPageAreas.theInk)) |
- (NOT EqualPt(fDeviceRes, oldDevRes)) | (oldPrinterDev = kNeverInitialized) THEN
- BEGIN { something important to our projection
- model changed... }
- msgSent := FALSE;
- IF fDocument <> NIL THEN
- IF fDocument.fSharePrintInfo THEN
- BEGIN
- fDocument.ForAllViewsDo(ItChanged);
- msgSent := TRUE;
- END;
-
- IF NOT msgSent THEN { didn't send msg to all views, current
- company included, so now we need to tell
- must my local view }
- fView.DoPrinterChanged;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintImage}
-
- PROCEDURE TStdPrintHandler.ChooseSpoolFile(VAR spoolFileName: Str255;
- VAR spoolVRefNum: INTEGER;
- VAR pagesPerSubjob: INTEGER);
-
- BEGIN
- spoolFileName := ''; { Default choices tell MacPrint to use its
- standard choice algorithm }
- spoolVRefNum := 0;
- { Print Shop suggests attempting to print entire document. If it
- runs out of space, then PerformPrinting will retry with a
- smaller number of pages. }
- pagesPerSubjob := MAXINT;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintRes}
-
- PROCEDURE TStdPrintHandler.ClosePrintShop;
-
- VAR
- err: OSErr;
-
- BEGIN
- PrClose;
- {$IFC qDebug}
- err := PrError; { Now check for fresh error from MacPrint --
- only for debugging, since ChkPrintErr
- checks afresh in the real world }
- IF err <> noErr THEN
- WriteLn('Error from MacPrint is: ', err: 1);
- {$ENDC}
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintRes}
-
- PROCEDURE TStdPrintHandler.DoInMacPrint(PROCEDURE WhatToDo);
-
- VAR
- fi: FailInfo;
-
- PROCEDURE HdlPrintFailure(error: OSErr;
- message: LONGINT);
-
- BEGIN
- ClosePrintShop;
- SetPort(gWorkPort); { Might be left looking at a dead port }
- gApplication.InvalidateFocus;
- END;
-
- BEGIN
- IF gCouldPrint THEN
- BEGIN
- PrSetError(noErr); { Clear printer-error flag }
- CatchFailures(fi, HdlPrintFailure);
- OpenPrintShop;
- WhatToDo; { Do what needs to be done }
- Success(fi);
- ClosePrintShop;
- SetPort(gWorkPort); { Might be left looking at a dead port }
- gApplication.InvalidateFocus;
- END;
- { NB: if gCouldPrint is FALSE, DoInMacPrint is a no-op }
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintSelCommand}
-
- FUNCTION TStdPrintHandler.DoMenuCommand(aCmdNumber: CmdNumber): TCommand; OVERRIDE;
-
- VAR
- proceed: BOOLEAN;
-
- FUNCTION LaunchPrintCommand(aCmdNumber: CmdNumber): TCommand;
-
- VAR
- aPrintCommand: TPrintCommand;
-
- BEGIN
- New(aPrintCommand);
- FailNIL(aPrintCommand);
- aPrintCommand.IPrintCommand(aCmdNumber, SELF);
- LaunchPrintCommand := aPrintCommand;
- END;
-
- BEGIN
- DoMenuCommand := NIL;
- CASE aCmdNumber OF
-
- cPrint:
- BEGIN
- CheckPrinter;
- IF PoseJobDialog THEN
- DoMenuCommand := LaunchPrintCommand(aCmdNumber);
- END;
- cPrintOne:
- BEGIN
- CheckPrinter;
- IF SetupPrintOne THEN
- DoMenuCommand := LaunchPrintCommand(aCmdNumber);
- END;
- cPageSetup:
- DoMenuCommand := PosePageSetupDialog(proceed, TRUE);
-
- cShowBreaks: { Toggle state of "Show Breaks" }
- BEGIN
- fShowBreaks := NOT fShowBreaks;
- InvalPageFeedback; { force redraw of area the breaks did or
- will occupy }
- END;
-
- OTHERWISE
- DoMenuCommand := INHERITED DoMenuCommand(aCmdNumber);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintRes}
-
- PROCEDURE TStdPrintHandler.DoSetupMenus; OVERRIDE;
-
- BEGIN
- INHERITED DoSetupMenus;
-
- IF gCouldPrint & (fView <> NIL) & (NOT MemSpaceIsLow) THEN
- BEGIN
- Enable(cPrint, TRUE);
- Enable(cPageSetup, TRUE);
- Enable(cPrintOne, TRUE);
- END;
-
- EnableCheck(cShowBreaks, TRUE, fShowBreaks);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintRes}
-
- PROCEDURE TStdPrintHandler.DrawPrintFeedback(area: Rect); OVERRIDE;
- { Draws page breaks and page numbers }
-
- VAR
- vhs: VHSelect;
- orthoVHS: VHSelect;
- whichBreak: INTEGER;
- viewArea: VRect;
- {$IFC qDebug}
- pageNumStyle: TextStyle;
- {$ENDC}
-
- {--------------------------------------------------------------------------------------------------}
-
- FUNCTION DrawABreak(loc: VCoordinate;
- automatic: BOOLEAN): BOOLEAN;
-
- BEGIN
- IF loc > viewArea.botRight.vh[orthoVHS] THEN
- DrawABreak := TRUE
- ELSE
- BEGIN
- DrawABreak := FALSE;
- whichBreak := whichBreak + 1;
- IF (loc > viewArea.topLeft.vh[orthoVHS] - gBreaksPenState.pnSize.vh[orthoVHS]) THEN
- fView.DoDrawPageBreak(vhs, whichBreak, loc, automatic);
- END;
- END;
-
- BEGIN
- IF qDebug THEN
- fView.AssumeFocused;
- IF fShowBreaks | gDebugPrinting THEN
- BEGIN
- SetPrintExtent; { Make sure print extent is accurate before
- starting }
-
- {$IFC qDebug}
- IF gDebugPrinting THEN { Now draw Page numbers in the corners of
- pages, if desired }
- BEGIN
- SetTextStyle(pageNumStyle, applFont, [bold], 9, gRGBBlack);
- SetPortTextStyle(pageNumStyle);
- END;
- {$ENDC}
-
- SetPenState(gBreaksPenState);
- fView.QDToViewRect(area, viewArea);
-
- FOR vhs := v TO h DO
- BEGIN
- orthoVHS := gOrthogonal[vhs];
- whichBreak := 0;
- EachBreak(vhs, FALSE, DrawABreak);
- END;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintRes}
-
- PROCEDURE TStdPrintHandler.DrawPageBreak(vhs: VHSelect;
- whichBreak: INTEGER;
- loc: VCoordinate;
- automatic: BOOLEAN); OVERRIDE;
-
- VAR
- vPt: VPoint;
- qdStartPt: Point;
- qdEndPt: Point;
- {$IFC qDebug}
- i: INTEGER;
- hLoc: VCoordinate;
- aString: Str255;
- theFontInfo: FontInfo;
- theTextRect: Rect;
- {$ENDC}
-
- BEGIN
- vPt.vh[gOrthogonal[vhs]] := loc;
- vPt.vh[vhs] := 0;
- qdStartPt := fView.ViewToQDPt(vPt);
- vPt.vh[vhs] := fView.fSize.vh[vhs] - gBreaksPenState.pnSize.vh[vhs];
- qdEndPt := fView.ViewToQDPt(vPt);
-
- IF fShowBreaks THEN
- BEGIN
- MoveTo(qdStartPt.h, qdStartPt.v);
- LineTo(qdEndPt.h, qdEndPt.v);
- END;
-
- {$IFC qDebug}
- IF gDebugPrinting THEN
- IF vhs = h THEN
- FOR i := 0 TO fPageStrips.v DO
- BEGIN
- IF i = 0 THEN
- hLoc := 0
- ELSE
- GetBreakCoord(v, i, hLoc);
-
- GetFontInfo(theFontInfo);
-
- NumToString(StripToPage(whichBreak - 1, i), aString);
- WITH theFontInfo, qdStartPt DO
- SetRect(theTextRect, hLoc + 3, v - 3 - ascent, { top computed based on the
- bottom - text height }
- hLoc + 3 + StringWidth(aString), v - 3 + descent);
- MADrawString(@aString, theTextRect, teJustSystem);
-
- NumToString(StripToPage(whichBreak, i), aString);
- WITH theFontInfo, qdEndPt DO
- SetRect(theTextRect, hLoc + 3, v + 10 - ascent, { top computed based on the
- bottom - text height }
- hLoc + 3 + StringWidth(aString), v + 10 + descent);
- MADrawString(@aString, theTextRect, teJustSystem);
-
- NumToString(StripToPage(whichBreak - 1, i - 1), aString);
- WITH theFontInfo, qdStartPt DO
- SetRect(theTextRect, hLoc - StringWidth(aString) - 3, v - 3 - ascent, { top
- computed based on the bottom - text height }
- hLoc - 3, v - 3 + descent);
- MADrawString(@aString, theTextRect, teJustSystem);
-
- NumToString(StripToPage(whichBreak, i - 1), aString);
- WITH theFontInfo, qdEndPt DO
- SetRect(theTextRect, hLoc - StringWidth(aString) - 3, v + 10 - ascent, { top
- computed based on the bottom - text height }
- hLoc - 3, v + 10 + descent);
- MADrawString(@aString, theTextRect, teJustSystem);
- END;
- {$ENDC}
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintImage}
-
- PROCEDURE TStdPrintHandler.DrawPageInterior;
-
- BEGIN
- fView.DrawContents; { i.e., by default, the same code used for
- drawing on the screen }
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintRes}
-
- PROCEDURE TStdPrintHandler.EachBreak(vhs: VHSelect;
- includeLast: BOOLEAN;
- FUNCTION DoToBreak(loc: VCoordinate;
- automatic: BOOLEAN): BOOLEAN);
-
- VAR
- startLoc: VCoordinate;
- endLoc: VCoordinate;
- loc: VCoordinate;
- automatic: BOOLEAN;
- done: BOOLEAN;
- prevBreak: VCoordinate;
-
- BEGIN
- WITH fPrintExtent DO
- BEGIN
- startLoc := topLeft.vh[gOrthogonal[vhs]];
- endLoc := botRight.vh[gOrthogonal[vhs]];
- END;
-
- loc := startLoc;
- automatic := TRUE;
- done := FALSE;
- WHILE (loc < endLoc) & NOT done DO
- BEGIN
- IF loc <> startLoc THEN
- done := DoToBreak(loc, automatic);
- IF qDebug THEN
- prevBreak := loc;
-
- loc := fView.DoBreakFollowing(vhs, loc, automatic);
-
- IF qDebug & (loc <= prevBreak) THEN
- ProgramBreak('thisBreak (loc) <= prevBreak'); { Thanks much to Larry T. ! }
- END;
-
- IF includeLast THEN
- done := DoToBreak(loc, automatic);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintFields}
-
- PROCEDURE TStdPrintHandler.Fields(PROCEDURE DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
-
- BEGIN
- DoToField('TStdPrintHandler', NIL, bClass);
- DoToField('fPageAreas', NIL, bTitle);
- DoToField(' thePaper', @fPageAreas.thePaper, bRect);
- DoToField(' theInk', @fPageAreas.theInk, bRect);
- DoToField(' theMargins', @fPageAreas.theMargins, bRect);
- DoToField(' theInterior', @fPageAreas.theInterior, bRect);
- DoToField('fPrintExtent', @fPrintExtent, bVRect);
- DoToField('fFixedSizePages[h]', @fFixedSizePages[h], bBoolean);
- DoToField('fFixedSizePages[v]', @fFixedSizePages[v], bBoolean);
- DoToField('fHPrint', @fHPrint, bHandle);
- DoToField('fPageStrips', @fPageStrips, bPoint);
- DoToField('fStartPage', @fStartPage, bInteger);
- DoToField('fPrinterDev', @fPrinterDev, bInteger);
- DoToField('fLastCheckedPrinter', @fLastCheckedPrinter, bLongInt);
- DoToField('fLastPrinterName', @fLastPrinterName, bStringHandle);
- DoToField('fPageDirection', @fPageDirection, bVHSelect);
- DoToField('fShowBreaks', @fShowBreaks, bBoolean);
- DoToField('fFinderSetup', @fFinderSetup, bBoolean);
- DoToField('fFinderJobDialog', @fFinderJobDialog, bBoolean);
- DoToField('fSquareDots', @fSquareDots, bBoolean);
- DoToField('fMinimalMargins', @fMinimalMargins, bBoolean);
- DoToField('fLastStrip', @fLastStrip, bPoint);
- DoToField('fLastBreak', @fLastBreak, bVPoint);
- DoToField('fViewedRect', @fViewedRect, bVRect);
- DoToField('fMarginRes', @fMarginRes, bPoint);
- DoToField('fPrintDialog', @fPrintDialog, bWindowPtr); { need a bDialogPtr }
-
- DoToField('fPPrPort', NIL, bTitle);
- IF fPPrPort <> NIL THEN
- BEGIN
- DoToField(' gPort', @fPPrPort, bGrafPtr);
- DoToField(' gProcs', NIL, bTitle);
- DoToField(' textProc', @fPPrPort^.gProcs.textProc, bPointer);
- DoToField(' lineProc', @fPPrPort^.gProcs.lineProc, bPointer);
- DoToField(' rectProc', @fPPrPort^.gProcs.rectProc, bPointer);
- DoToField(' rRectProc', @fPPrPort^.gProcs.rRectProc, bPointer);
- DoToField(' ovalProc', @fPPrPort^.gProcs.ovalProc, bPointer);
- DoToField(' arcProc', @fPPrPort^.gProcs.arcProc, bPointer);
- DoToField(' polyProc', @fPPrPort^.gProcs.polyProc, bPointer);
- DoToField(' rgnProc', @fPPrPort^.gProcs.rgnProc, bPointer);
- DoToField(' bitsProc', @fPPrPort^.gProcs.bitsProc, bPointer);
- DoToField(' commentProc', @fPPrPort^.gProcs.commentProc, bPointer);
- DoToField(' txMeasProc', @fPPrPort^.gProcs.txMeasProc, bPointer);
- DoToField(' getPicProc', @fPPrPort^.gProcs.getPicProc, bPointer);
- DoToField(' putPicProc', @fPPrPort^.gProcs.putPicProc, bPointer);
- DoToField(' IGParam1', @fPPrPort^.lGParam1, bLongInt);
- DoToField(' IGParam2', @fPPrPort^.lGParam2, bLongInt);
- DoToField(' IGParam3', @fPPrPort^.lGParam3, bLongInt);
- DoToField(' IGParam4', @fPPrPort^.lGParam4, bLongInt);
- DoToField(' fOurPtr', @fPPrPort^.fOurPtr, bBoolean);
- DoToField(' fOurBits', @fPPrPort^.fOurBits, bBoolean);
- END;
- INHERITED Fields(DoToField);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintImage}
-
- PROCEDURE TStdPrintHandler.FocusOnBorder;
-
- VAR
- rectToClipTo: Rect;
-
- BEGIN
- rectToClipTo := fPageAreas.theInk;
- WITH fPageAreas.theInk DO
- {$Push} {$H-}
- SetOrigin(left, top); { Only works for newer LaserWriter drivers }
- {$Pop}
- ClipRect(rectToClipTo);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintImage}
-
- PROCEDURE TStdPrintHandler.FocusOnInterior; OVERRIDE;
-
- VAR
- rectToClip: Rect;
- aRect: Rect;
- theOrigin: Point;
- vhs: VHSelect;
- aVRect: VRect;
-
- BEGIN
- {$Push} {$H-}
- WITH fPageAreas DO
- BEGIN
- aRect := theInk;
- theOrigin := theInk.topLeft;
- FOR vhs := v TO h DO
- IF fView.fSize.vh[vhs] > kMaxCoord THEN
- gLongOffset.vh[vhs] := gPageOffset.vh[vhs]
- ELSE
- BEGIN
- gLongOffset.vh[vhs] := 0;
- theOrigin.vh[vhs] := theOrigin.vh[vhs] + gPageOffset.vh[vhs];
- aRect.topLeft.vh[vhs] := aRect.topLeft.vh[vhs] + gPageOffset.vh[vhs];
- aRect.botRight.vh[vhs] := aRect.botRight.vh[vhs] + gPageOffset.vh[vhs];
- END;
- END;
- {$Pop}
- SetOrigin(theOrigin.h, theOrigin.v);
-
- { Clip the page to the intersection of the visible part of the view and the
- printable area of the page. Note that in some cases (e.g., a WYSIWYG
- word processor which showed the complete page margin) parts of
- the interior might lie outside theInk. We must clip to theInk to
- avoid slowing down PostScript printers. }
- aVRect := fViewedRect;
- fView.ViewToQDRect(aVRect, rectToClip);
- IF SectRect(rectToClip, aRect, rectToClip) THEN;
- ClipRect(rectToClip);
-
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintRes}
-
- PROCEDURE TStdPrintHandler.GetBreakCoord(vhs: VHSelect;
- whichBreak: INTEGER;
- VAR loc: VCoordinate);
-
- VAR
- automatic: BOOLEAN;
- i: INTEGER;
- startBreak: INTEGER;
- orthoVHS: VHSelect;
- prevBreak: VCoordinate;
-
- BEGIN
- orthoVHS := gOrthogonal[vhs];
- IF fFixedSizePages[orthoVHS] THEN
- loc := fPrintExtent.topLeft.vh[orthoVHS] + fViewPerPage.vh[orthoVHS] * whichBreak
- ELSE IF whichBreak = fLastStrip.vh[vhs] THEN
- loc := fLastBreak.vh[vhs]
- ELSE
- BEGIN
- IF whichBreak > fLastStrip.vh[vhs] THEN
- BEGIN
- startBreak := fLastStrip.vh[vhs] + 1;
- loc := fLastBreak.vh[vhs];
- END
- ELSE
- BEGIN
- startBreak := 1;
- loc := fPrintExtent.topLeft.vh[gOrthogonal[vhs]];
- END;
- FOR i := startBreak TO whichBreak DO
- BEGIN
- IF qDebug THEN
- prevBreak := loc;
-
- loc := fView.DoBreakFollowing(vhs, loc, automatic); { ??? error handling??? }
-
- IF qDebug & (loc <= prevBreak) THEN
- ProgramBreak('thisBreak (loc) <= prevBreak');
- END;
- END;
- loc := Min(loc, fPrintExtent.botRight.vh[orthoVHS]);
-
- fLastStrip.vh[vhs] := whichBreak;
- fLastBreak.vh[vhs] := loc;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintActual}
-
- PROCEDURE TStdPrintHandler.GetDocName(VAR docName: Str255);
-
- VAR
- aWindow: TWindow;
-
- BEGIN
- IF fDocument <> NIL THEN
- docName := fDocument.fTitle^^
- ELSE
- docName := '';
- IF docName = '' THEN
- BEGIN
- aWindow := fView.GetWindow;
- IF aWindow <> NIL THEN
- aWindow.GetTitle(docName);
- END;
- {$IFC qDebug}
- IF docName = '' THEN
- ProgramBreak('GetDocName can''t get a document or window name');
- {$ENDC}
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintDebug}
-
- PROCEDURE TStdPrintHandler.IdentifySoftware;
-
- BEGIN
- WRITELN('UPrinting of 14 Feb 90 (Valentine''s Day), Compiled on ', COMPDATE, ' @ ', COMPTIME);
-
- INHERITED IdentifySoftware;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintNonRes}
-
- PROCEDURE TStdPrintHandler.InstallMargins(newMargins: Rect;
- areMinimalMargins: BOOLEAN);
-
- BEGIN
- fMinimalMargins := areMinimalMargins;
-
- IF fMinimalMargins THEN
- BEGIN
- WITH fPageAreas DO
- BEGIN
- {$Push} {$H-}
- theMargins := theInk;
- SubPt(thePaper.topLeft, theMargins.topLeft);
- SubPt(thePaper.botRight, theMargins.botRight);
- {$Pop}
- END;
- WITH fPageAreas DO
- theInterior := theInk;
- END
- ELSE
- BEGIN
- fPageAreas.theMargins := newMargins;
- WITH fPageAreas DO
- BEGIN
- theInterior := thePaper;
- {$Push} {$H-}
- AddPt(theMargins.topLeft, theInterior.topLeft);
- AddPt(theMargins.botRight, theInterior.botRight);
- {$Pop}
- END;
- END;
-
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintNonRes}
-
- PROCEDURE TStdPrintHandler.InvalPageFeedback;
-
- BEGIN
- IF ShowsOnScreen THEN
- fView.ForceRedraw;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintNonRes}
-
- PROCEDURE TStdPrintHandler.LocatePageInterior(pageNumber: INTEGER;
- VAR loc: Point); OVERRIDE;
-
- BEGIN
- WITH fPageAreas DO
- BEGIN
- loc := thePaper.topLeft;
- {$Push} {$H-}
- AddPt(theMargins.topLeft, loc);
- {$Pop}
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintActual}
-
- FUNCTION TStdPrintHandler.MaxPageNumber: INTEGER; OVERRIDE;
-
- BEGIN
- WITH fPageStrips DO
- MaxPageNumber := fStartPage + (v * h) - 1;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintActual}
-
- FUNCTION TStdPrintHandler.OneSubJob(subjobFirstPage, subjobLastPage: INTEGER;
- justSpool: BOOLEAN;
- partialJob: BOOLEAN;
- VAR ranOutOfSpace: BOOLEAN;
- VAR lastPageTried: INTEGER;
- VAR proceed: BOOLEAN): TCommand;
-
- LABEL 1000;
-
- VAR
- pass: INTEGER;
- noOfCopies: INTEGER;
- aPageNumber: INTEGER;
- err: OSErr;
- fi: FailInfo;
- {--------------------------------------------------------------------------------------------------}
-
- PROCEDURE FieldClientError(error: OSErr;
- message: LONGINT);
-
- BEGIN
- proceed := FALSE;
- err := error; { pass along client's error code } {Why???}
- GOTO 1000;
- END;
-
- BEGIN
- {$IFC qDebug}
- IF gDebugPrinting THEN
- WriteLn('OneSubJob entered for pages ', subjobFirstPage: 1, ' through ', subjobLastPage: 1,
- ', proceed=', ORD(proceed): 0);
- {$ENDC}
- OneSubJob := NIL;
- ranOutOfSpace := FALSE;
- lastPageTried := subjobFirstPage - 1;
- WITH THPrint(fHPrint)^^.PrJob DO
- BEGIN
- iFstPage := 1;
- iLstPage := subjobLastPage - subjobFirstPage + 1;
-
- IF bjDocLoop = BSpoolLoop THEN
- noOfCopies := 1
- ELSE
- noOfCopies := iCopies;
- END;
- fPPrPort := PrOpenDoc(THPrint(fHPrint), NIL, NIL);
- { ??? need to allow/encourage app to supply nonNil args? }
- ChkPrintErr(err, proceed, ranOutOfSpace);
- gCurrPrintHandler := SELF;
-
- IF proceed THEN
- BEGIN
- fView.InvalidateFocus;
- gPrinting := TRUE;
- SetPort(GrafPtr(fPPrPort));
- fView.BeInPort(GrafPtr(fPPrPort));
-
- gPrinting := TRUE;
- IF NOT fView.Focus THEN
- BEGIN
- {$IFC qDebug}
- ProgramBreak('Can''t focus view while printing');
- {$ENDC}
- END;
- FOR pass := 1 TO noOfCopies DO
- BEGIN
- FOR aPageNumber := subjobFirstPage TO subjobLastPage DO
- IF proceed THEN
- BEGIN
- lastPageTried := aPageNumber;
- CatchFailures(fi, FieldClientError);
- PrintPage(aPageNumber);
- Success(fi);
- 1000:
- ChkPrintErr(err, proceed, ranOutOfSpace);
- END;
- END;
- gPrinting := FALSE;
- fView.InvalidateFocus;
- fView.BeInPort(fView.GetGrafPort);
- END;
-
- gCurrPrintHandler := NIL;
- PrCloseDoc(fPPrPort); { This will close the port! }
- SetPort(gWorkPort);
- ChkPrintErr(err, proceed, ranOutOfSpace);
-
- IF ranOutOfSpace THEN
- Exit(OneSubJob)
- ELSE IF proceed THEN
- BEGIN
- IF THPrint(fHPrint)^^.PrJob.bjDocLoop = BSpoolLoop THEN
- IF NOT justSpool THEN
- PrintSpoolFile(fHPrint, err, proceed);
- END;
- IF NOT proceed THEN
- IF err <> iPrAbort THEN
- Failure(err, 0);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintRes}
-
- PROCEDURE TStdPrintHandler.OpenPrintShop;
-
- VAR
- err: OSErr;
-
- BEGIN
- PrOpen; { Open the print shop }
- err := PrError; { Get code }
- IF err <> noErr THEN
- BEGIN
- IF (err = fnfErr) | (err = resFNotFound) THEN
- err := errNoPrintDrvr;
- Failure(err, 0);
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintRes}
-
- FUNCTION TStdPrintHandler.PageToStrip(pageNumber: INTEGER): Point;
-
- VAR
- normalizedPageNum: INTEGER;
- ortho: VHSelect;
- strip: Point;
-
- BEGIN
- normalizedPageNum := pageNumber - fStartPage + 1;
-
- ortho := gOrthogonal[fPageDirection];
-
- strip.vh[ortho] := ((normalizedPageNum - 1) DIV fPageStrips.vh[ortho]);
- strip.vh[fPageDirection] := normalizedPageNum - ((strip.vh[ortho]) * fPageStrips.vh[ortho]) - 1;
-
- PageToStrip := strip;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintRes}
-
- FUNCTION TStdPrintHandler.PointToPageStrip(pointInView: VPoint): Point;
- { !!! Need to test this! }
-
- VAR
- loc: INTEGER;
- automatic: BOOLEAN;
- aStrip: INTEGER;
- vhs: VHSelect;
- pageStrip: Point;
- prevBreak: VCoordinate;
-
- BEGIN
- FOR vhs := v TO h DO
- IF fFixedSizePages[vhs] THEN
- pageStrip.vh[vhs] := (pointInView.vh[vhs] DIV fViewPerPage.vh[vhs]) + 1
- ELSE
- BEGIN
- pageStrip.vh[vhs] := 1;
- loc := fPrintExtent.topLeft.vh[vhs]; { ??? or orthogonal? }
- WHILE pointInView.vh[vhs] > loc DO { ??? or orthogonal? }
- BEGIN
- IF qDebug THEN
- prevBreak := loc;
-
- loc := fView.DoBreakFollowing(vhs, loc, automatic);
-
- IF qDebug & (loc <= prevBreak) THEN
- ProgramBreak('thisBreak (loc) <= prevBreak');
-
- pageStrip.vh[vhs] := aStrip + 1;
- END;
- END;
- PointToPageStrip := pageStrip;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintActual}
-
- FUNCTION TStdPrintHandler.PoseJobDialog: BOOLEAN;
-
- VAR
- b: BOOLEAN;
- proceed: BOOLEAN;
- temp: INTEGER;
- err: OSErr;
-
- PROCEDURE CallJobDialog;
-
- BEGIN
- SetCursor(arrow);
- IF gApplication <> NIL THEN
- gApplication.InvalidateCursorRgn;
-
- proceed := PrJobDialog(THPrint(fHPrint));
- END;
-
- BEGIN
- proceed := TRUE;
- { PrepareForDialog; }
- DoInMacPrint(CallJobDialog);
- ChkPrintErr(err, proceed, b);
-
- WITH THPrint(fHPrint)^^.PrJob DO
- IF iFstPage > iLstPage THEN { Rectify the range as a public service if
- needed }
- BEGIN
- temp := iLstPage;
- iLstPage := iFstPage;
- iFstPage := temp;
- END;
-
- gApplication.UpdateAllWindows;
- PoseJobDialog := proceed;
- END;
-
- {$S PrintActual} { Needs to be here because it may be called
- from Print }
- {--------------------------------------------------------------------------------------------------}
-
- FUNCTION TStdPrintHandler.PosePageSetupDialog(VAR proceed: BOOLEAN;
- isUndoable: BOOLEAN): TCommand;
-
- VAR
- react: BOOLEAN;
- aPrintStyleChangeCommand: TPrintStyleChangeCommand;
-
- PROCEDURE CallStyleDialog;
-
- BEGIN
- SetCursor(arrow);
- IF gApplication <> NIL THEN
- gApplication.InvalidateCursorRgn;
-
- react := PrStlDialog(THPrint(fHPrint));
- END;
-
- BEGIN
- PosePageSetupDialog := NIL;
- react := FALSE; { in case MacPrint code not accessible }
- IF NOT isUndoable THEN
- BEGIN
- { PrepareForDialog; }
- DoInMacPrint(CallStyleDialog);
- IF react THEN
- CheckPrinter;
- END
- ELSE
- BEGIN
- { Must setup command before putting up page setup dialog because the
- command records the current print record to make it undoable. }
- New(aPrintStyleChangeCommand);
- FailNIL(aPrintStyleChangeCommand);
- aPrintStyleChangeCommand.IPrintStyleChangeCommand(SELF);
-
- { PrepareForDialog; }
- DoInMacPrint(CallStyleDialog); { Put up the Page Setup Dialog }
-
- IF react THEN { User specified a change }
- BEGIN
- BlockMove(fHPrint^, aPrintStyleChangeCommand.fNewHPrint^, SIZEOF(TPrint));
- PosePageSetupDialog := aPrintStyleChangeCommand;
- END
-
- ELSE { User did not specify a change }
- BEGIN
- FreeIfObject(aPrintStyleChangeCommand);
- aPrintStyleChangeCommand := NIL;
- END;
-
- END;
- proceed := react;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintActual}
-
- PROCEDURE TStdPrintHandler.PosePrintDialog;
-
- VAR
- dlgNumber: INTEGER;
- dlogTemplate: DialogTHndl;
- docName: Str255;
- itemNo: INTEGER;
- theItem: Handle;
- itemType: INTEGER;
- box: Rect;
- itemText: Str255;
- preDocName, constTitle: INTEGER;
-
- BEGIN
- IF gFinderPrinting THEN
- BEGIN
- dlgNumber := phFinderPrintDialog;
- itemNo := 3;
- END
- ELSE
- BEGIN
- dlgNumber := phSpoolPrintDialog;
- itemNo := 2;
- END;
-
- { Can't use GetNewCenteredDialog because vertically centering the dialog may cause it
- to interfere with the Print Manager's status windows. Therefore, leave the vertical
- location of the dialog fixed. }
-
- SetCursor(arrow);
- gApplication.InvalidateCursorRgn;
- dlogTemplate := DialogTHndl(GetResource('DLOG', dlgNumber));
- IF dlogTemplate <> NIL THEN
- BEGIN
- CenterRectOnScreen(dlogTemplate^^.boundsRect, TRUE, FALSE, FALSE);
- fPrintDialog := GetNewDialog(dlgNumber, NIL, POINTER( - 1));
- FailNIL(fPrintDialog);
- END
- ELSE
- BEGIN
- {$IFC qDebug}
- WriteLn('You may have forgotten to include Printing.rsrc in your .r file…');
- ProgramBreak('The print job dialog resource can''t be found.');
- {$ENDC}
- FailNilResource(dlogTemplate);
- END;
-
- { Substitute the document name for '<<<>>>' in 'Document “<<<>>>” is being printed'.
- ParamText would be a lot simpler, but the Print Mgr. also uses ParamText, and
- the substitution doesn't happen until draw time.}
- GetDocName(docName);
- GetDItem(fPrintDialog, itemNo, itemType, theItem, box);
- IF theItem <> NIL THEN
- BEGIN
- GetIText(theItem, itemText);
- IF ParseTitleTemplate(itemText, preDocName, constTitle) & SubstituteInTitle(itemText,
- docName, preDocName, constTitle) THEN
- SetIText(theItem, itemText);
- END;
-
- THPrint(fHPrint)^^.PrJob.pIdleProc := @IdleProcForTStdPrintHandler;
- SetWTitle(fPrintDialog, docName); { In case Print Mgr. needs it. }
- DrawDialog(fPrintDialog);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintRes}
- { ???Was in PrintActual. Doesn't really belong in this segment, but
- can get unloaded during Finder printing otherwise. }
-
- FUNCTION TStdPrintHandler.Print(itsCmdNumber: CmdNumber;
- VAR proceed: BOOLEAN): TCommand; OVERRIDE;
-
- VAR
- fi: FailInfo;
-
- PROCEDURE DoPrint;
-
- VAR
- firstPage: INTEGER;
- lastPage: INTEGER;
- err: OSErr;
- spoolFileName: Str255;
- spoolVRefNum: INTEGER;
- aPrJob: TPrJob;
- totalPages: INTEGER;
- lastPrinted: INTEGER;
- lastAttempted: INTEGER;
- pagesPerSubjob: INTEGER;
- firstSubjobPage: INTEGER;
- proceed: BOOLEAN;
- ranOutOfSpace: BOOLEAN;
- spoolMethod: BOOLEAN;
- justSpool: BOOLEAN;
- dontCare: BOOLEAN;
- pageStrips: Point;
- fi: FailInfo;
-
- PROCEDURE HdlSubjobFailure(error: OSErr;
- message: LONGINT);
-
- BEGIN
- BanishPrintDialog;
- END;
-
- BEGIN
- gJobPrintHandler := SELF; { be visible to the idleProc }
- justSpool := (itsCmdNumber = cPrintToFile);
- proceed := TRUE;
- ranOutOfSpace := FALSE;
- aPrJob := THPrint(fHPrint)^^.PrJob;
- fView.DoCalcPageStrips(pageStrips);
- fPageStrips := pageStrips;
-
- firstPage := MAX(aPrJob.iFstPage, fStartPage);
- lastPage := Min(aPrJob.iLstPage, MaxPageNumber);
-
- IF lastPage < firstPage THEN
- err := Alert(phNoPages, NIL)
- ELSE
- BEGIN
- totalPages := lastPage - firstPage + 1;
- spoolMethod := (aPrJob.bjDocLoop = BSpoolLoop);
- IF spoolMethod THEN
- BEGIN
- ChooseSpoolFile(spoolFileName, spoolVRefNum, pagesPerSubjob);
- IF NOT justSpool THEN { if justSpool is true, then the spool
- filename & vRefNum will already have been
- stuffed into the prJob record before this
- method is called }
- BEGIN
- IF spoolFileName <> '' THEN
- WITH THPrint(fHPrint)^^.PrJob DO
- BEGIN
- pFileName := @spoolFileName;
- iFileVol := spoolVRefNum;
- END;
- END;
- END
- ELSE
- pagesPerSubjob := MAXINT;
-
- lastPrinted := firstPage - 1;
-
- pagesPerSubjob := Min(pagesPerSubjob, totalPages);
- PosePrintDialog;
-
- CatchFailures(fi, HdlSubjobFailure);
- REPEAT
- firstSubjobPage := lastPrinted + 1;
- Print := OneSubJob(firstSubjobPage, firstSubjobPage + pagesPerSubjob - 1, justSpool,
- (pagesPerSubjob < totalPages), ranOutOfSpace, lastAttempted,
- proceed);
- IF proceed THEN
- lastPrinted := lastAttempted;
- IF ranOutOfSpace THEN
- BEGIN
- pagesPerSubjob := lastAttempted - 1 - firstSubjobPage;
- proceed := TRUE;
- END;
- UNTIL (lastPrinted = lastPage) | (pagesPerSubjob < 1) | NOT proceed;
-
- IF pagesPerSubjob < 1 THEN
- Failure(errSpooling, 0);
- Success(fi);
- BanishPrintDialog; { having removed, put back here, unsure if
- exactly right }
- END; { if there are pages within requested range
- }
-
- gJobPrintHandler := NIL; { out damned spot }
- END;
-
- {--------------------------------------------------------------------------------------------------}
-
- PROCEDURE HdlPrintFailure(error: OSErr;
- message: LONGINT);
-
- BEGIN
- { Certain Print Manager errors should not result in any alert,
- since the Print Manager will have already put one up. }
- IF (error >= - 8160) & (error <= - 8150) THEN
- Failure(0, msgPrintFailed);
- IF message = 0 THEN
- GetDocName(gErrorParm3);
- FailNewMessage(error, message, msgPrintFailed);
- END;
-
- BEGIN { TStdPrintHandler.Print }
- Print := NIL;
- gCancelAllPrinting := FALSE;
-
- SetPrintExtent; { Make sure we've got the right area. }
-
- CatchFailures(fi, HdlPrintFailure);
- DoInMacPrint(DoPrint);
- Success(fi);
- proceed := NOT gCancelAllPrinting;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintNonRes}
-
- PROCEDURE TStdPrintHandler.PrinterChanged; OVERRIDE;
-
- BEGIN
- fView.DoPagination;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintImage}
-
- PROCEDURE TStdPrintHandler.PrintPage(aPageNumber: INTEGER); { Print a single page }
-
- VAR
- {$IFC qDebug}
- aPort: GrafPtr;
- {$ENDC}
- fi: FailInfo;
-
- PROCEDURE CheckPrintFailure;
-
- BEGIN
- FailOSErr(PrError);
- END;
-
- PROCEDURE HdlPrintFailure(error: OSErr;
- message: LONGINT);
-
- BEGIN
- PrClosePage(fPPrPort);
- END;
-
- BEGIN
- SetPage(aPageNumber); { gets gPage set up correctly for coordinate
- transformations }
- CatchFailures(fi, HdlPrintFailure);
- PrOpenPage(fPPrPort, NIL);
- CheckPrintFailure;
- FocusOnInterior;
- DrawPageInterior;
- {$IFC qDebug}
- GetPort(aPort);
- IF aPort <> GrafPtr(fPPrPort) THEN
- ProgramBreak('The view''s DrawPageInterior method changed the grafPort');
- {$ENDC}
- CheckPrintFailure;
- FocusOnBorder;
- AdornPage;
- CheckPrintFailure;
- Success(fi);
- PrClosePage(fPPrPort);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintNonRes}
-
- PROCEDURE TStdPrintHandler.RedoPageBreaks; OVERRIDE;
- { Called from fView.DoPagination. }
-
- VAR
- worryAboutBreaks: BOOLEAN;
- oldViewPerPage, viewPerPage: VPoint;
- pageStrips: Point;
- newInterior, oldInterior: Rect;
-
- BEGIN
- worryAboutBreaks := (fView.GetGrafPort <> NIL) & gInitialized & (fShowBreaks | gDebugPrinting);
-
- IF worryAboutBreaks THEN
- InvalPageFeedback; { invalidate old page breaks, if relevant }
-
- SetPrintExtent;
- oldInterior := fPageAreas.theInterior;
- oldViewPerPage := fViewPerPage;
- SetMargins;
-
- { computes view per page from papersize, printer resolution, margins desired, view resolution,
- and, if desired, other factors such as printable rectangle of page and font metrics in the
- printer space }
- fView.DoCalcViewPerPage(viewPerPage);
- fViewPerPage := viewPerPage;
- SetPageInterior(kUsualPages);
- newInterior := fPageAreas.theInterior;
-
- {$IFC qDebug}
- IF gDebugPrinting THEN
- IF NOT EqualRect(oldInterior, newInterior) THEN
- ProgramBreak('Setting new interior');
- {$ENDC}
-
- IF NOT EqualRect(oldInterior, newInterior) THEN
- fView.PageInteriorChanged(newInterior);
-
- {$IFC qDebug}
- IF gDebugPrinting THEN
- IF NOT EqualVPt(oldViewPerPage, viewPerPage) THEN
- ProgramBreak('Setting new view per page');
- {$ENDC}
-
- IF NOT EqualRect(oldInterior, newInterior) | NOT EqualVPt(oldViewPerPage, viewPerPage) THEN
- fView.AdjustSize;
-
- fView.DoCalcPageStrips(pageStrips);
- fPageStrips := pageStrips;
-
- IF worryAboutBreaks THEN
- InvalPageFeedback; { force redraw of new page breaks, if
- relevant }
-
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintNonRes}
-
- PROCEDURE TStdPrintHandler.Reset;
- { subclass may stuff some special values by redefining this }
-
- LABEL 1000;
-
- TYPE
- TXWord = PACKED RECORD
- CASE INTEGER OF
- 0:
- (c1, c0: CHAR);
- 1:
- (b1, b0: SignedByte);
- 2:
- (f15, f14, f13, f12, f11, f10, f9, f8, f7, f6, f5, f4, f3, f2, f1, f0: BOOLEAN);
- 3:
- (i0: INTEGER);
- END;
-
- VAR
- anHPrint: THPrint;
- didChange: BOOLEAN;
- inited: BOOLEAN;
- fi: FailInfo;
-
- PROCEDURE CallPrintDefault;
-
- BEGIN
- PrintDefault(anHPrint);
- END;
-
- PROCEDURE HdlDefaultError(error: OSErr;
- message: LONGINT);
-
- BEGIN
- GOTO 1000;
- END;
-
- BEGIN
- anHPrint := THPrint(fHPrint);
- inited := FALSE;
- IF anHPrint <> NIL THEN
- BEGIN
- IF gCouldPrint THEN
- BEGIN
- CatchFailures(fi, HdlDefaultError);
- DoInMacPrint(CallPrintDefault);
- IF fSquareDots THEN
- WITH TXWord(THPrint(anHPrint)^^.prStl.wDev) DO
- IF b1 = 1 THEN { 1 = bDevCItoh => ImageWriter }
- BEGIN
- { Set the square-pixel flag in the print record, then
- ensure we didn't corrupt it. }
- f2 := TRUE;
- ValidatePrintRecord(didChange);
- END;
- inited := TRUE;
- Success(fi);
- END;
- 1000:
- IF NOT (gCouldPrint & inited) THEN
- { MacPrint code unavailable, but we want some plausible things
- anyway - set up for Portrait Tall Adj. }
- BEGIN
- { ??? Replace the following expensive stuffing code with StuffHex
- calls or a GetResource or some such, later }
- WITH anHPrint^^ DO
- {$Push} {$H-}
- BEGIN
- iPrVersion := 0; { something invalid }
-
- WITH prInfo DO
- BEGIN
- iHRes := 72;
- iVRes := 72;
- SetRect(rPage, 0, 0, 576, 752); { must have its top left @ (0,0) }
- END;
-
- SetRect(rPaper, - 18, - 36, 594, 756);
-
- WITH prStl DO
- BEGIN
- iPageV := 1320; { 11 inches in 120th of an inch }
- iPageH := 1020; { 8.5 inches in 120th of an inch }
- END;
- {$Pop}
- END;
- END;
-
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintNonRes}
-
- PROCEDURE TStdPrintHandler.SetPrintExtent;
-
- VAR
- printExtent: VRect;
-
- BEGIN
- fView.GetPrintExtent(printExtent);
- { Make sure the bottom or right is not smaller than the top or left.
- This can happen when views are being created and before the window
- has been resized to its actual size. }
- printExtent.bottom := MAX(printExtent.bottom, printExtent.top);
- printExtent.right := MAX(printExtent.right, printExtent.left);
- fPrintExtent := printExtent;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintOpen}
-
- PROCEDURE TStdPrintHandler.SetDefaultPrintInfo;
-
- VAR
- didChange: BOOLEAN;
- wantValidate: BOOLEAN;
- anHPrint: THPrint;
- haveHPrint: BOOLEAN;
-
- BEGIN
- fHPrint := DisposeIfHandle(fHPrint);
- wantValidate := FALSE;
-
- haveHPrint := FALSE;
- IF fView <> NIL THEN
- BEGIN
- IF fDocument <> NIL THEN
- IF fDocument.fSharePrintInfo & (fDocument.fPrintInfo <> NIL) THEN
- BEGIN
- fHPrint := fDocument.fPrintInfo;
- haveHPrint := TRUE;
- END;
- END;
-
- IF haveHPrint THEN
- wantValidate := TRUE
- ELSE
- BEGIN
- fHPrint := NewPermHandle(SIZEOF(TPrint));
- FailNIL(fHPrint);
- Reset;
- END;
-
- IF wantValidate THEN
- ValidatePrintRecord(didChange);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintNonRes}
-
- PROCEDURE TStdPrintHandler.SetMargins;
-
- VAR
- someMargins: Rect;
-
- BEGIN
- someMargins := fPageAreas.theMargins; { Prevent heap scramble }
- InstallMargins(someMargins, fMinimalMargins);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintImage}
-
- PROCEDURE TStdPrintHandler.SetPage(aPageNumber: INTEGER);
-
- VAR
- viewedRect: VRect;
- vhs: VHSelect;
- strip: Point;
- {$IFC qDebug}
- aRect: Rect;
- {$ENDC}
-
- BEGIN
- fFocusedPage := aPageNumber;
-
- strip := PageToStrip(aPageNumber);
- FOR vhs := v TO h DO
- BEGIN
- GetBreakCoord(gOrthogonal[vhs], strip.vh[vhs], viewedRect.topLeft.vh[vhs]);
- GetBreakCoord(gOrthogonal[vhs], strip.vh[vhs] + 1, viewedRect.botRight.vh[vhs]);
- END;
-
- SetPageInterior(aPageNumber);
- fView.DoSetPageOffset(viewedRect.topLeft);
- fViewedRect := viewedRect;
-
- {$IFC qDebug}
- IF gDebugPrinting THEN
- BEGIN
- Write('pg #: ', aPageNumber: 1);
- Write('; coord = ');
- WriteVPt(viewedRect.topLeft);
- Write('Page Interior: ');
- aRect := fPageAreas.theInterior;
- WriteRect(aRect); { ???HS }
- WriteLn;
- END;
- {$ENDC}
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintNonRes}
-
- PROCEDURE TStdPrintHandler.SetPageInterior(pageNumber: INTEGER); OVERRIDE;
-
- VAR
- vhs: VHSelect;
- pegPoint: Point;
-
- BEGIN
- WITH fPageAreas, theInterior DO
- BEGIN
- FOR vhs := v TO h DO
- BEGIN
- topLeft.vh[vhs] := thePaper.topLeft.vh[vhs] + theMargins.topLeft.vh[vhs];
- botRight.vh[vhs] := topLeft.vh[vhs] + fViewPerPage.vh[vhs];
- END;
- END;
-
- LocatePageInterior(pageNumber, pegPoint);
- WITH fPageAreas.theInterior DO
- BEGIN
- topLeft := pegPoint;
- FOR vhs := v TO h DO
- botRight.vh[vhs] := topLeft.vh[vhs] + fViewPerPage.vh[vhs];
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintImage}
-
- PROCEDURE TStdPrintHandler.SetPageOffset(coord: VPoint); OVERRIDE;
-
- VAR
- vhs: VHSelect;
-
- BEGIN
- FOR vhs := v TO h DO
- gPageOffset.vh[vhs] := coord.vh[vhs] - fPageAreas.theInterior.topLeft.vh[vhs];
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintFinder}
-
- FUNCTION TStdPrintHandler.SetupForFinder: BOOLEAN; OVERRIDE;
-
- VAR
- proceed: BOOLEAN;
- didChange: BOOLEAN;
-
- BEGIN
- proceed := TRUE;
- CheckPrinter; { Uncertain if necessary??? }
-
- IF fFinderSetup THEN
- IF PosePageSetupDialog(proceed, FALSE) <> NIL THEN
- {$IFC qDebug}
- ProgramBreak('PosePageSetupDialog returned real command.')
- {$ENDC} ;
-
- IF proceed THEN
- BEGIN
- ShowDocBeingPrinted(TRUE);
-
- IF fFinderJobDialog | (gFinderHPrint = NIL) THEN
- BEGIN
- proceed := PoseJobDialog;
- { Merge into gPrintHandler, in case next document needs it }
- IF gFinderHPrint = NIL THEN
- BEGIN
- gFinderHPrint := NewPermHandle(SIZEOF(TPrint));
- FailNIL(gFinderHPrint);
- END;
- BlockMove(fHPrint^, gFinderHPrint^, SIZEOF(TPrint));
- END
- ELSE
- BEGIN
- PrJobMerge(THPrint(gFinderHPrint), THPrint(fHPrint));
- ValidatePrintRecord(didChange);
- END;
-
- ShowDocBeingPrinted(FALSE);
- END;
- SetupForFinder := proceed;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintRes}
-
- FUNCTION TStdPrintHandler.SetupPrintOne: BOOLEAN;
-
- VAR
- didChange: BOOLEAN;
-
- BEGIN
- { Call PrValidate to 1) make sure the record is OK, and
- 2) Get the LaserWriter driver to get the name of the
- front window. }
- ValidatePrintRecord(didChange);
-
- PrSetError(noErr);
- WITH THPrint(fHPrint)^^.PrJob DO
- BEGIN
- iFstPage := 0;
- iLstPage := 9999; { This is what the Print Mgr. uses }
- END;
- SetupPrintOne := TRUE; { Should always be able to continue from
- here }
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintFinder}
-
- PROCEDURE TStdPrintHandler.ShowDocBeingPrinted(entering: BOOLEAN);
-
- VAR
- aTitle: Str255;
-
- BEGIN
- IF entering THEN
- BEGIN
- fPrintDialog := GetNewDialog(phWhichDoc, NIL, POINTER( - 1));
- IF fPrintDialog <> NIL THEN
- BEGIN
- GetDocName(aTitle);
- SetWTitle(fPrintDialog, aTitle);
- DrawDialog(fPrintDialog);
- END
- {$IFC qDebug}
- ELSE
- ProgramBreak(ConcatNumber('Unable to load dialog ', phWhichDoc))
- {$ENDC} { semicolon } ;
- END
- ELSE
- BanishPrintDialog;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintRes}
-
- FUNCTION TStdPrintHandler.ShowsOnScreen: BOOLEAN;
-
- BEGIN
- IF fView <> NIL THEN
- ShowsOnScreen := fView.GetWindow <> NIL
- ELSE
- ShowsOnScreen := FALSE;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintRes}
-
- FUNCTION TStdPrintHandler.StripToPage(hStrip, vStrip: INTEGER): INTEGER;
-
- VAR
- strip: Point;
- ortho: VHSelect;
-
- BEGIN
- SetPt(strip, hStrip, vStrip);
- ortho := gOrthogonal[fPageDirection];
- StripToPage := strip.vh[fPageDirection] * fPageStrips.vh[ortho] + strip.vh[ortho] + fStartPage;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintRes}
-
- PROCEDURE TStdPrintHandler.ValidatePrintRecord(VAR didChange: BOOLEAN);
-
- VAR
- fi: FailInfo;
-
- PROCEDURE CallPrValidate;
-
- BEGIN
- didChange := PrValidate(THPrint(fHPrint));
- END;
-
- PROCEDURE HdlValidateFailed(error: OSErr;
- message: LONGINT);
-
- BEGIN
- Reset;
- Exit(ValidatePrintRecord);
- END;
-
- BEGIN
- CatchFailures(fi, HdlValidateFailed);
- DoInMacPrint(CallPrValidate);
- Success(fi);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintDoCommand}
-
- PROCEDURE TPrintStyleChangeCommand.IPrintStyleChangeCommand(itsPrintHandler: TStdPrintHandler);
-
- VAR
- fi: FailInfo;
-
- PROCEDURE HdlInitFailed(error: OSErr;
- message: LONGINT);
-
- BEGIN
- Free;
- END;
-
- BEGIN
- fStdPrintHandler := itsPrintHandler;
- fOldHPrint := NIL;
- fNewHPrint := NIL;
- ICommand(cChangePrinterStyle, itsPrintHandler.fDocument, itsPrintHandler.fView, NIL);
- fCausesChange := (fChangedDocument <> NIL) & (fChangedDocument.fSavePrintInfo);
- CatchFailures(fi, HdlInitFailed);
- fOldHPrint := NewPermHandle(SIZEOF(TPrint));
- FailNIL(fOldHPrint);
- { Make a copy of the old version of the PrintInfo record }
- BlockMove(itsPrintHandler.fHPrint^, fOldHPrint^, SIZEOF(TPrint));
- fNewHPrint := NewPermHandle(SIZEOF(TPrint));
- FailNIL(fNewHPrint);
- Success(fi);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintDoCommand}
-
- PROCEDURE TPrintStyleChangeCommand.Free; OVERRIDE;
-
- BEGIN
- fOldHPrint := DisposeIfHandle(fOldHPrint);
- fNewHPrint := DisposeIfHandle(fNewHPrint);
- INHERITED Free;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintDoCommand}
-
- PROCEDURE TPrintStyleChangeCommand.DoIt; OVERRIDE;
-
- BEGIN
- fStdPrintHandler.CheckPrinter; { Will find it changed, and hence dispatch
- to view's DoPrinterChanged }
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintFields}
-
- PROCEDURE TPrintStyleChangeCommand.Fields(PROCEDURE
- DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
-
- BEGIN
- DoToField('TPrintStyleChangeCommand', NIL, bClass);
- DoToField('fStdPrintHandler', @fStdPrintHandler, bObject);
- DoToField('fOldHPrint', @fOldHPrint, bHandle);
- DoToField('fNewHPrint', @fNewHPrint, bHandle);
- INHERITED Fields(DoToField);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintDoCommand}
-
- PROCEDURE TPrintStyleChangeCommand.UndoIt; OVERRIDE;
-
- BEGIN
- BlockMove(fOldHPrint^, fStdPrintHandler.fHPrint^, SIZEOF(TPrint));
- fStdPrintHandler.CheckPrinter; { Will find it changed, and hence dispatch
- to view's DoPrinterChanged }
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S PrintDoCommand}
-
- PROCEDURE TPrintStyleChangeCommand.RedoIt; OVERRIDE;
-
- BEGIN
- BlockMove(fNewHPrint^, fStdPrintHandler.fHPrint^, SIZEOF(TPrint));
- fStdPrintHandler.CheckPrinter; { Will find it changed, and hence dispatch
- to view's DoPrinterChanged }
- END;
-